package com.battery.system.service.battery.impl;

import java.util.List;
import java.util.ArrayList;

import com.battery.common.core.domain.Ztree;
import com.battery.common.utils.DateUtils;
import com.battery.system.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.battery.system.mapper.StoreSiteMapper;
import com.battery.system.domain.StoreSite;
import com.battery.system.service.battery.IStoreSiteService;
import com.battery.common.core.text.Convert;

/**
 * 门店类别Service业务层处理
 *
 * @author battery
 * @date 2021-01-22
 */
@Service
public class StoreSiteServiceImpl extends BaseServiceImpl<StoreSite> implements IStoreSiteService {
    @Autowired
    private StoreSiteMapper storeSiteMapper;

    /**
     * 查询门店类别
     *
     * @param id 门店类别ID
     * @return 门店类别
     */
    @Override
    public StoreSite selectStoreSiteById(Long id) {
        return storeSiteMapper.selectStoreSiteById(id);
    }

    /**
     * 查询门店类别列表
     *
     * @param storeSite 门店类别
     * @return 门店类别
     */
    @Override
    public List<StoreSite> selectStoreSiteList(StoreSite storeSite) {
        return storeSiteMapper.selectStoreSiteList(storeSite);
    }

    /**
     * 新增门店类别
     *
     * @param storeSite 门店类别
     * @return 结果
     */
    @Override
    public int insertStoreSite(StoreSite storeSite) {
        storeSite.setCreateTime(DateUtils.getNowDate());
        return storeSiteMapper.insertStoreSite(storeSite);
    }

    /**
     * 修改门店类别
     *
     * @param storeSite 门店类别
     * @return 结果
     */
    @Override
    public int updateStoreSite(StoreSite storeSite) {
        storeSite.setUpdateTime(DateUtils.getNowDate());
        return storeSiteMapper.updateStoreSite(storeSite);
    }

    /**
     * 删除门店类别对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteStoreSiteByIds(String ids) {
        return storeSiteMapper.deleteStoreSiteByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除门店类别信息
     *
     * @param id 门店类别ID
     * @return 结果
     */
    @Override
    public int deleteStoreSiteById(Long id) {
        return storeSiteMapper.deleteStoreSiteById(id);
    }

    /**
     * 查询门店类别树列表
     *
     * @return 所有门店类别信息
     */
    @Override
    public List<Ztree> selectStoreSiteTree() {
        List<StoreSite> storeSiteList = storeSiteMapper.selectStoreSiteList(new StoreSite());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (StoreSite storeSite : storeSiteList) {
            Ztree ztree = new Ztree();
            ztree.setId(storeSite.getId() + "");
            ztree.setpId(storeSite.getParentId() + "");
            ztree.setName(storeSite.getName());
            ztree.setTitle(storeSite.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
